<?php

declare(strict_types=1);
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2020/1/15
 * Time: 11:13 AM
 */

namespace App\Entity;

use App\Models\Payment;

class PaymentEntity extends ABaseEntity
{
    public function __construct(Payment $payment)
    {
        $this->model = $payment;
    }

    /**
     * @return PaymentEntity
     */
    public static function findByTradeNo(string $tradeNo)
    {
        $model = Payment::where('trade_no', $tradeNo)->first();
        if ($model === null) {
            return null;
        }

        return new self($model);
    }

    public function getId(): int
    {
        return $this->model->id;
    }

    /**
     * 支付记录状态
     */
    public function getState(): int
    {
        return $this->model->state;
    }

    public function setState(int $value)
    {
        $this->model->state = $value;
    }

    /**
     * 支付方式
     */
    public function getPaymentMethod(): string
    {
        return $this->model->payment_method;
    }

    /**
     * 支付方式
     */
    public function setPaymentMethod(string $value)
    {
        $this->model->payment_method = $value;
    }

    /**
     * 交易号
     */
    public function getTradeNo(): string
    {
        return $this->model->trade_no;
    }

    /**
     * 交易号
     */
    public function setTradeNo(string $value)
    {
        $this->model->trade_no = $value;
    }

    /**
     * 交易号
     */
    public function getRefundTradeNo(): string
    {
        return $this->model->refund_trade_no ?: '';
    }

    public function setRefundTradeNo(string $value)
    {
        $this->model->refund_trade_no = $value;
    }

    /**
     * 第三方交易号
     */
    public function getOutTradeNo(): string
    {
        return $this->model->out_trade_no;
    }

    public function setOutTradeNo(string $value)
    {
        $this->model->out_trade_no = $value;
    }

    /**
     * 第三方交易号
     */
    public function getOutRefundTradeNo(): string
    {
        return $this->model->out_refund_trade_no ?: '';
    }

    public function setOutRefundTradeNo(string $value)
    {
        $this->model->out_refund_trade_no = $value;
    }

    /**
     * 支付时间
     */
    public function getPaidAt(): string
    {
        return $this->model->paid_at ?: '';
    }

    public function setPaidAt(string $value)
    {
        $this->model->paid_at = $value;
    }

    /**
     * 退款时间
     */
    public function getRefundAt(): string
    {
        return $this->model->refund_at ?: '';
    }

    public function setRefundAt(string $value)
    {
        $this->model->refund_at = $value;
    }

    /**
     * 金额，以 分 为单位
     */
    public function getAmount(): int
    {
        return $this->model->amount;
    }

    public function setAmount(int $value)
    {
        $this->model->amount = $value;
    }
}
